<template>
  <div class="list">
    <!-- <div class="bg"></div> -->
    <div class="new-header">
      <div class="left">
        <span>新闻</span>
        <span>中心</span>
        <span>NEWS</span>
      </div>
      <div class="right">
        <span>当前位置:</span>
        &nbsp; &nbsp;
        <span @click="toOtherPage('/Index')">首页</span>
        &nbsp; &nbsp;
        <span>></span>
        &nbsp; &nbsp;
        <span>新闻中心</span>
      </div>
    </div>
    <div class="news-box">
      <div class="each-news" v-for="item in newsList" :key="item.did" @click="toDetail(item.did)">
        <div class="cover">
          <img :src="item.cover" alt="图片" />
        </div>
        <div class="time">{{ formatter(item.createTime) }}</div>
        <div class="title">{{ item.title }}</div>
        <div class="brief">{{ item.summary }}</div>
      </div>
    </div>
    <div class="page">
      <el-pagination
        background
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :total="count"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  nameL: "list",
  data() {
    return {
      newsList: [],
      count: 0,
      currentPage: 1
    };
  },
  methods: {
    toOtherPage(path) {
      this.$router.push(path);
    },
    //跳转详情
    toDetail(did) {
      this.$router.push({
        path: "/NewsDetail",
        query: {
          did: did
        }
      });
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getNewsList();
      window.scrollTo(0, 0);
    },
    formatter(dates) {
      if (dates == "0") {
        return "-";
      } else {
        var date = new Date(dates);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? "0" + m : m;
        var d = date.getDate();
        d = d < 10 ? "0" + d : d;
        let hour = date.getHours();
        if (hour < 10) {
          hour = "0" + hour;
        }
        let minute = date.getMinutes();
        if (minute < 10) {
          minute = "0" + minute;
        }
        let second = date.getSeconds();
        if (second < 10) {
          second = "0" + second;
        }
        return y + "-" + m + "-" + d + "\xa0 ";
      }
    },
    getNewsList() {
      this.$post("/v1/news/list", {
        page: this.currentPage,
        pageSize: 10
      }).then(res => {
        if (res.code == 200) {
          const { data } = res;
          this.newsList = data.news;
          this.count = data.count;
        }
      });
    }
  },
  mounted() {
    this.$parent.setNav(6, 0);
    this.getNewsList();
  }
};
</script>
<style lang="less" scoped>
.list {
  background: #eff7fe;
  padding-bottom: 1rem;
  text-align: center;
  .bg {
    height: 1.1rem;
    background: url("../../../public/static/news-bg.png") no-repeat center;
    background-size: cover;
  }
  .new-header {
    width: 15.18rem;
    margin: 0 auto;
    padding: 0.6rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .left {
      font-size: 0.36rem;
      span {
        font-weight: 600;
        &:first-child {
          color: #1d73e6;
        }
        &:nth-child(2) {
          color: #000;
        }
        &:last-child {
          color: #a8a8a9;
        }
      }
    }
    .right {
      font-size: 0.18rem;
      span {
        &:nth-child(2) {
          cursor: pointer;
        }
      }
    }
  }
  .news-box {
    width: 15.2rem;
    margin: 0 auto 1.15rem;
    display: flex;
    flex-wrap: wrap;
  }
  .each-news {
    padding: 0.2rem 0.2rem 0.8rem;
    width: 3.65rem;
    box-sizing: border-box;
    text-align: left;
    cursor: pointer;
    background: #fff;
    margin-bottom: 0.3rem;
    margin-right: 0.2rem;
    box-shadow: 1px 1px 5px 0 rgba(29, 39, 165, 0.33);
    &:nth-child(4n) {
      margin-right: 0;
    }
    &:hover {
      background: #1a72e6;
    }
    &:hover .title {
      color: #fff;
    }
    &:hover .time {
      color: #fff;
    }
    &:hover .brief {
      color: #fff;
    }
    &:hover .more {
      color: #fff;
    }
    .cover {
      // width: 3.2rem;
      height: 2.23rem;
      margin-bottom: 0.5rem;
      img {
        width: 100%;
        height: 100%;
        vertical-align: middle;
      }
    }
    .time {
      font-size: 0.18rem;
    }
    .title {
      font-size: 0.24rem;
      font-weight: 600;
      margin: 0.24rem 0 0.29rem;
      line-height: 0.3rem;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .brief {
      font-size: 0.18rem;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      line-height: 0.26rem;
    }
  }

  /deep/.el-pager li {
    width: 0.5rem;
    height: 0.5rem;
    line-height: 0.5rem;
    background: #d4e5f3;
  }
  /deep/.el-pagination button {
    width: 0.5rem;
    height: 0.5rem;
    line-height: 0.5rem;
    background: #d4e5f3;
  }
  /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
    background: #1a72e6;
  }
}
@media screen and (max-width: 1000px) {
  .list {
    .new-header {
      width: 100%;
      padding: 0.6rem 0.2rem;
      box-sizing: border-box;
      // margin: 0.3rem 0;
      .right {
        font-size: 0.24rem;
      }
    }
    .news-box {
      width: 100%;
      padding: 0 0.2rem;
      box-sizing: border-box;
      flex-wrap: wrap;
      justify-content: space-between;
      .each-news {
        width: 48%;
        margin-right: 0;
      }
    }
    .detail-box {
      .head {
        width: 100%;
        padding: 0.2rem;
        box-sizing: border-box;
      }
      width: 100%;
      padding: 0 0.2rem;
      box-sizing: border-box;
    }
  }
}
</style>